<?php
									 require '../config/dbconfig.php';

									$data = unserialize(base64_decode($_POST['data']));
									$id_page = $_POST['id'];
									//$data = base64_decode($_POST['data']);
									$contestants_array = array();  
									foreach ($data as $item) {
										$contestants_array[] = $item['id'];
									}
									$contestants = implode(",", $contestants_array);
								   //get the contestants associated with the challenge
									$sqlquery=sprintf("SELECT * FROM splash_contestants WHERE id IN ($contestants) ORDER BY votes"); 
									$result = mysql_query($sqlquery) or die ("no query");
									$result_array = array();
									while($row = mysql_fetch_assoc($result))
									{
										$result_array[] = $row;
									}
									foreach ($result_array as $row) {
									
										$user_id = $row['splash_contestant_user_id'];
										$contestant_username_query = mysql_query("SELECT username, oauth_uid FROM users WHERE id = '$user_id'");
										//Get user info
										while ($row_getcontestantuser= mysql_fetch_assoc($contestant_username_query)) {
											$contestant_username = $row_getcontestantuser['username'];
											$contestant_oauth = $row_getcontestantuser['oauth_uid'];
										}
										$votes = $row['votes'];
										$contestant_id = $row['id'];
										$filepath = $row['image'];
										$cont_description = $row['description'];
									  ?>
                                      
									
                                   <li class="battle_item <?= $id_page ?>">
                                        <div>
                                            <input type="radio" name="vote" value="<?php  echo $contestant_id ?>" >
                                            <a href="<?php echo $filepath ?>" title="<?php echo $cont_description ?>" class="preview"></a>
                                            <p class="hover"><span><?php echo $votes ?><div class="popup" style="position:absolute;width:100px;height:200px;background-color: #45484d;border-radius:5px;-webkit-border-radius:5px;-moz-border-radius:5px; display:none;z-index:1;">
                                            	<p><span><img src="https://graph.facebook.com/<?php echo $contestant_oauth; ?>/picture?type=large" /><?php echo $contestant_username ?></span></p>
                                            </div></span></p>
                                            <!--Hover over votes, the contestant user info pops us-->
                                            
                                            <img src="<?php echo $filepath ?>" />
                                        </div>
                                    </li>
                                   
                                   <?php } ?>